package com.sghd.football.module.game.service.match;

import com.sghd.common.socket.core.Message;
import com.sghd.common.socket.session.SessionManager;
import com.sghd.football.module.game.service.core.Player;
import com.sghd.football.net.SocketEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wch
 * @date 2018-07-03 14:12
 * @desc 默认匹配器
 **/
@Component
public class DefaultMatcher extends AbstractMatcher {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SessionManager sessionManager;

    @Override
    protected void doMatch() {
        for (Player player : players.values()) {
            try {
                gameService.conn(player);
            } catch (Exception e) {
                logger.error("玩家[{}]进入房间[{}]发生未知错误！", player.getPlayerId(), player.getRoomId(), new Object[]{e});
            }
            sessionManager.send(Message.Empty(SocketEnum.CONN), player.getPlayerId());
        }
        if(!players.isEmpty()){
            players.clear();
        }
    }
}
